//
//  SetMainHomeVC.m
//  Doctor
//
//  Created by 阳光 on 16/9/6.
//  Copyright © 2016年 阳光. All rights reserved.
//

#import "SetMainHomeVC.h"
#import "ResetPasswordVC.h"
#import "AboutUSVC.h"

#import "RegisterVC.h"
#import "LoginVC.h"
#import "ConfirmVC.h"
#import "ReviewVC.h"
#import "DoctorInfoVC.h"

#import "ResetPdVC.h"

static NSString *tableViewCellIdentifier=@"TableViewCellIdentifier";

@interface SetMainHomeVC ()<UIAlertViewDelegate,UIScrollViewDelegate>

@property(nonatomic,strong)UIView *resetPdView;

@property(nonatomic,strong)UIView *aboutUSView;

@end



@implementation SetMainHomeVC

- (void)viewDidLoad
{
    [super viewDidLoad];
   
    self.title = NSLocalizedString(@"Settings", nil);//@"设置";
    
    self.view.backgroundColor=MAIN_BACK_COLOR;
    
//    [self initNavBarBtnItem];
    
    [self initMainView];

}

-(void)initMainView
{
    // 修改密码
    {
        _resetPdView=[UIView new];
        _resetPdView.backgroundColor=WhiteColor;
        [self.view addSubview:_resetPdView];
        [_resetPdView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(kmargin);
            make.size.mas_equalTo(CGSizeMake(APPW,kmargin*5));
        }];
        
        UILabel *resetPdLabel=[self.view getLabelWithText:NSLocalizedString(@"Change Password", nil) font:Font_Number(16) textColor:Color000000 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];//@"修改密码"
        [_resetPdView addSubview:resetPdLabel];
        [resetPdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.mas_equalTo(kmargin);
            make.bottom.mas_equalTo(-kmargin);
        }];
        
        UIImageView *arrowImage=[UIImageView new];
        [_resetPdView addSubview:arrowImage];
        arrowImage.image=[UIImage imageNamed:@"cell_arrow"];
        [arrowImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-kmargin);
            make.size.mas_equalTo(CGSizeMake(kmargin*3/2,kmargin*3/2));
            make.centerY.mas_equalTo(resetPdLabel.mas_centerY);
        }];
        
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(resetPdViewEvent)];
        [_resetPdView addGestureRecognizer:tap];
        
    }
    
    // 关于我们
    {
        _aboutUSView=[UIView new];
        _aboutUSView.backgroundColor=WhiteColor;
        [self.view addSubview:_aboutUSView];
        [_aboutUSView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.resetPdView.mas_bottom).offset(kmargin);
            make.size.mas_equalTo(CGSizeMake(APPW,kmargin*5));
        }];
        
        UILabel *aboutUSLabel=[self.view getLabelWithText:NSLocalizedString(@"About Us", nil) font:Font_Number(16) textColor:Color000000 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];//@"关于我们"
        [_aboutUSView addSubview:aboutUSLabel];
        [aboutUSLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.mas_equalTo(kmargin);
            make.bottom.mas_equalTo(-kmargin);
        }];
        
        UIImageView *arrowImage=[UIImageView new];
        [_aboutUSView addSubview:arrowImage];
        arrowImage.image=[UIImage imageNamed:@"cell_arrow"];
        [arrowImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-kmargin);
            make.size.mas_equalTo(CGSizeMake(kmargin*3/2,kmargin*3/2));
            make.centerY.mas_equalTo(aboutUSLabel.mas_centerY);
        }];
        
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(aboutUSViewEvent)];
        [_aboutUSView addGestureRecognizer:tap];
    }
    
    // 退出登录
    {
        UIButton *exitBtn=[UIButton new];
        [self.view addSubview:exitBtn];
        exitBtn.backgroundColor=WhiteColor;
        exitBtn.titleLabel.font=Font_Number(16);
        [exitBtn setTitle:NSLocalizedString(@"Log Out", nil) forState:UIControlStateNormal];//@"退出登录"
        [exitBtn setTitleColor:Color000000 forState:UIControlStateNormal];
        [exitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.aboutUSView.mas_bottom).offset(kmargin);
            make.size.mas_equalTo(CGSizeMake(APPW,kmargin*5));
        }];
        [exitBtn addTarget:self action:@selector(exitBtnEvent) forControlEvents:UIControlEventTouchUpInside];
    }
}

-(void)initNavBarBtnItem
{
    // 添加论文
    self.navigationItem.rightBarButtonItem=[UIBarButtonItem initWithNormalImage:@"add" target:self action:@selector(addItemEvent)];
}

-(void)addItemEvent
{
    // 跳转登录界面
    LoginVC *loginVC=[LoginVC new];
    [self.navigationController pushViewController:loginVC animated:NO];
    
    // 跳转注册界面
//    RegisterVC *registerVC=[RegisterVC new];
//    [self.navigationController pushViewController:registerVC animated:NO];
    
        // 跳转注册界面
//       ConfirmVC *confirmVC=[ConfirmVC new];
//      [self.navigationController pushViewController:confirmVC animated:NO];

        // 跳转审核界面
//        ReviewVC *reviewVC=[ReviewVC new];
//        [self.navigationController pushViewController:reviewVC animated:NO];
    
    // 跳转个人信息界面
//    DoctorInfoVC *doctorInfoVC=[DoctorInfoVC new];
//    [self.navigationController pushViewController:doctorInfoVC animated:NO];

}


-(void)exitBtnEvent
{
    UIAlertController *alertController=[UIAlertController alertControllerWithTitle:NSLocalizedString(@"Warning", nil) message:NSLocalizedString(@"Log Out Alert", nil) preferredStyle:UIAlertControllerStyleAlert];//@"警告";@"你确定要退出登录吗?"
    UIAlertAction *cancelAction=[UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil];//@"取消"
    UIAlertAction *okAction=[UIAlertAction actionWithTitle:NSLocalizedString(@"Sure", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {//@"确定"
         
        
        [self ExitCurrentAccount];//.
         
     }];
    
    [alertController addAction:cancelAction];
    [alertController addAction:okAction];
    [self presentViewController:alertController animated:NO completion:nil];
}



//退出登录；
-(void)ExitCurrentAccount{
    
    AppDelegate *delegate=(AppDelegate *)[UIApplication sharedApplication].delegate;
    [delegate clearUserData];
    
     [self gotoLoginAction];
    
}

- (void)gotoLoginAction{
    
    LoginVC *login = [[LoginVC alloc] init];
    [self presentViewController:login animated:YES completion:nil];
    
}
//.



-(void)aboutUSViewEvent
{
    // 跳到关于我们界面
    AboutUSVC *aboutUSVC=[AboutUSVC new];
    [self.navigationController pushViewController:aboutUSVC animated:NO];
}

-(void)resetPdViewEvent
{
    // 跳到修改密码界面
    ResetPdVC *resetPdVC=[ResetPdVC new];
    [self.navigationController pushViewController:resetPdVC animated:NO];
//    ResetPasswordVC *resetPasswordVC=[ResetPasswordVC new];
//    [self.navigationController pushViewController:resetPasswordVC animated:NO];
}

@end
